//
//  VipInfo1ViewController.m
//  fitnessmanage
//
//  Created by 众拳科技 on 2017/10/27.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//  出勤记录

#import "VipInfo1ViewController.h"
#import "YZPullDownMenu.h"
#import "YZMenuButton.h"
#import "VipInfoTabViewController.h"
#import "VipInfoOutWorkView.h"
#import "AttendanceTableViewCell.h"

@interface VipInfo1ViewController ()<YZPullDownMenuDataSource,UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) NSArray *titles;

@property (nonatomic,strong)NSMutableArray *dataSource;

@property (nonatomic,strong)NoDataView *noDataViimg_girl_chooseew;

@end

@implementation VipInfo1ViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.view.backgroundColor = BackGroundColor;
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    // 创建下拉菜单
    YZPullDownMenu *menu = [[YZPullDownMenu alloc] init];
    //menu.frame = CGRectMake(0, 0, SCREEN_WIDTH, 44);
    menu.backgroundColor = CSWhiteColor;
    menu.separateLineColor = LineBackGroundColor;
    [self.view addSubview:menu];
    [menu mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.left.width.mas_equalTo(self.view);
        make.height.mas_equalTo(50);
    }];
    
    // 设置下拉菜单代理
    menu.dataSource = self;
    
    // 初始化标题
    _titles = @[@"测试",@"类型",@"状态",@"日期"];
    
    // 添加子控制器
    [self setupAllChildViewController];
    
    VipInfoOutWorkView *outWorkView = [[VipInfoOutWorkView alloc] init];
    outWorkView.outWorkLabel.text = @"出勤(天)";
    VipInfoOutWorkView *signView = [[VipInfoOutWorkView alloc] init];
    signView.outWorkLabel.text = @"签到(天)";
    VipInfoOutWorkView *classView = [[VipInfoOutWorkView alloc] init];
    classView.outWorkLabel.text = @"团课(节)";
    VipInfoOutWorkView *privateView = [[VipInfoOutWorkView alloc] init];
    privateView.outWorkLabel.text = @"私教(节)";
    [self.view addSubview:outWorkView];
    [self.view addSubview:signView];
    [self.view addSubview:classView];
    [self.view addSubview:privateView];
    [outWorkView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(menu.mas_bottom);
        make.left.mas_equalTo(self.view);
    }];
    [signView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(outWorkView);
        make.left.mas_equalTo(outWorkView.mas_right);
        make.width.mas_equalTo(outWorkView);
    }];
    [classView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(outWorkView);
        make.left.mas_equalTo(signView.mas_right);
        make.width.mas_equalTo(outWorkView);
    }];
    [privateView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(outWorkView);
        make.left.mas_equalTo(classView.mas_right);
        make.right.mas_equalTo(self.view);
        make.width.mas_equalTo(outWorkView);
    }];
    
//    UIButton *publicBtn = [[UIButton alloc] init];
//    [publicBtn setTitle:@"代约团课"];
//    [publicBtn setTitleColor:ButtonBackGroundColor];
//    publicBtn.titleLabel.font = BigFont;
//    publicBtn.backgroundColor = CSColorFromRGB(0x0a0a0a);
//    [self.view addSubview:publicBtn];
//    [publicBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.left.mas_equalTo(self.view);
//        make.height.mas_equalTo(50);
//    }];
//
//    UIButton *privateBtn = [[UIButton alloc] init];
//    [privateBtn setTitle:@"代约私教"];
//    [privateBtn setTitleColor:CSColorFromRGB(0x0a0a0a)];
//    privateBtn.titleLabel.font = BigFont;
//    privateBtn.backgroundColor = ButtonBackGroundColor;
//    [self.view addSubview:privateBtn];
//    [privateBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
//        make.top.width.height.mas_equalTo(publicBtn);
//        make.left.mas_equalTo(publicBtn.mas_right);
//        make.right.mas_equalTo(self.view);
//    }];
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    tableView.dataSource = self;
    tableView.delegate = self;
    tableView.showsVerticalScrollIndicator = NO;
    [tableView registerClass:[AttendanceTableViewCell class] forCellReuseIdentifier:@"AttendanceTableViewCell"];
    tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    tableView.backgroundColor = CSClearColor;
    [self.view addSubview:tableView];
    [tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(outWorkView.mas_bottom);
        make.left.width.mas_equalTo(self.view);
        make.bottom.mas_equalTo(self.view);
    }];
    
    
    NoDataView *noDataView = [NoDataView shareInstance];
    
    [self.view addSubview:noDataView];
    
    [noDataView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(outWorkView.mas_bottom);
        make.left.width.mas_equalTo(self.view);
        make.bottom.mas_equalTo(self.view);
    }];
}

-(void)loadData{
    
    //GET_SignRecordListData
}

#pragma mark - 添加子控制器
- (void)setupAllChildViewController
{
    VipInfoTabViewController *vc1 = [[VipInfoTabViewController alloc] init];
    vc1.titleArray = [NSMutableArray arrayWithObjects:@"全部", nil];
    vc1.colCount = 0;
    VipInfoTabViewController *vc2 = [[VipInfoTabViewController alloc] init];
    vc2.titleArray = [NSMutableArray arrayWithObjects:@"全部",@"团课",@"私教",@"自由训练", nil];
    vc2.colCount = 1;
    VipInfoTabViewController *vc3 = [[VipInfoTabViewController alloc] init];
    vc3.titleArray = [NSMutableArray arrayWithObjects:@"全部",@"已预约",@"以取消",@"以完成",@"以签课",@"以签到",@"以签出", nil];
    vc3.colCount = 2;
    VipInfoTabViewController *vc4 = [[VipInfoTabViewController alloc] init];
    vc4.titleArray = [NSMutableArray arrayWithObjects:@"不限",@"今日",@"最近7天",@"最近30天",@"自定义", nil];
    vc4.colCount = 3;
    
    [self addChildViewController:vc1];
    [self addChildViewController:vc2];
    [self addChildViewController:vc3];
    [self addChildViewController:vc4];
}

#pragma mark - YZPullDownMenuDataSource
// 返回下拉菜单多少列
- (NSInteger)numberOfColsInMenu:(YZPullDownMenu *)pullDownMenu
{
    return _titles.count;
}

// 返回下拉菜单每列按钮
- (UIButton *)pullDownMenu:(YZPullDownMenu *)pullDownMenu buttonForColAtIndex:(NSInteger)index
{
    YZMenuButton *button = [YZMenuButton buttonWithType:UIButtonTypeCustom];
    button.titleLabel.font = MidFont;
    [button setTitle:_titles[index] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor colorWithRed:25 /255.0 green:143/255.0 blue:238/255.0 alpha:1] forState:UIControlStateSelected];
    [button setImage:[UIImage imageNamed:@"more_icon_arrow_down"] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"more_icon_arrow_up"] forState:UIControlStateSelected];
    
    return button;
}

// 返回下拉菜单每列对应的控制器
- (UIViewController *)pullDownMenu:(YZPullDownMenu *)pullDownMenu viewControllerForColAtIndex:(NSInteger)index
{
    return self.childViewControllers[index];
}

// 返回下拉菜单每列对应的高度
- (CGFloat)pullDownMenu:(YZPullDownMenu *)pullDownMenu heightForColAtIndex:(NSInteger)index
{
    // 第1列 高度
    if (index == 0) {
        
        return 120;
    }
    
    else if (index == 1){
        
        return 180;
    }
    else if (index == 3){
        
        VipInfoTabViewController *vc = self.childViewControllers[index];
        
        if (vc.isTableShow) {
        
            return 210;
        }
        else{
            
            return 100;
        }
    }
    
    return 300;
}


#pragma mark UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataSource.count;
}

#pragma mark UITableViewDelegate
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.00001;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 40;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 90;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *headView = [[UIView alloc] init];
    headView.backgroundColor = BackGroundColor;
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = MidFont;
    NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];//实例化一个NSDateFormatter对象
    [dateFormat setDateFormat:@"yyyy年MM月"];//设定时间格式,这里可以设置成自己需要的格式
    NSString *currentDateStr = [dateFormat stringFromDate:[NSDate date]];
    titleLabel.text = currentDateStr;
    titleLabel.textColor = CSColorFromRGB(0x000000);
    [headView addSubview:titleLabel];
    [titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(headView).offset(15);
        make.centerY.mas_equalTo(headView);
    }];
    
    UILabel *countLabel = [[UILabel alloc] init];
    countLabel.font = MidFont;
    countLabel.text = @"0次签到 / 0节团课 / 0节私教";
    countLabel.textColor = CSColorFromRGB(0x000000);
    [headView addSubview:countLabel];
    [countLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(headView);
        
        make.right.mas_equalTo(headView).offset(-10);
    }];
    return headView;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    AttendanceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AttendanceTableViewCell"];
    
    
    NSString *currentDate = [self.dataSource objectAtIndex:indexPath.row];
    NSString *beforeTime = nil;
    NSString *endTime = nil;
    if (indexPath.row < self.dataSource.count - 1) {
        //最后一个
        endTime = [self.dataSource objectAtIndex:indexPath.row + 1];
    }
    if (indexPath.row > 0) {
        
        beforeTime = [self.dataSource objectAtIndex:indexPath.row - 1];
    }
    [cell setBrforeTiem:beforeTime andStartTime:currentDate andEndTime:endTime];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}


#pragma mark get
-(NSMutableArray *)dataSource{
    
    if (!_dataSource) {
        
        _dataSource = [[NSMutableArray alloc] init];
        
//        int K = 0;
//
//        for (int i = 0; i < 20; i++) {
//
//            if (i == 4 || i == 5|| i == 6 || i == 7 || i == 8 ) {
//
//
//            }
//            else{
//
//                K = i;
//            }
//
//            [_dataSource addObject:[NSString stringWithFormat:@"%d",K]];
//        }
    }
    
    return _dataSource;
}
@end
